home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / Libraries / SpriteWorld / SpriteWorld files / Utils Pascal / SWApplication.p next >
Text File  |  1996-11-02  |  4KB  |  150 lines

  1. unit SWApplication;
  2.  
  3. interface
  4.  
  5. {$IFC undefined THINK_Pascal}
  6.     uses
  7.         Types;
  8. {$ENDC}
  9.  
  10. {/--------------------------------------------------------------------------------------}
  11. {    SWApplication.h}
  12. {}
  13. {    Created:    Sunday, April 11, 1993}
  14. {    By:        Tony Myles}
  15. {}
  16. {    Portions Copyright: © 1993 Tony Myles, All rights reserved worldwide.}
  17. {/--------------------------------------------------------------------------------------}
  18.  
  19.  
  20.     const
  21.         kNumberOfMoreMastersCalls = 3;
  22.         kWindowResID = 128;
  23.  
  24.         kErrorAlertResID = 128;
  25.         kCantRunAlertResID = 129;
  26.         kErrorStringListResID = 128;
  27.         kFatalErrorStringIndex = 1;
  28.         kCantFindResourceStringIndex = 2;
  29.         kOutOfMemStringIndex = 3;
  30.         kSeriousDamageString = 'Could not even get error string!\rThis application is seriously damaged!';
  31.  
  32.     procedure Initialize (numberOfMasters: integer);
  33.     procedure ErrorAlert (err: OSErr; errorStringIndex: integer);
  34.     procedure FatalError (err: OSErr);
  35.     procedure CantFindResource;
  36.     procedure CantRunOnThisMachine;
  37.  
  38. implementation
  39. { /-------------------------------------------------------------------------------------- }
  40. {     Initialize }
  41. { /-------------------------------------------------------------------------------------- }
  42.  
  43. {$IFC undefined THINK_Pascal}
  44.     uses
  45.         Events, Memory, Quickdraw, Fonts, Windows, Menus, TextEdit, Dialogs, {}
  46.         TextUtils, Errors, SegLoad, Resources;
  47. {$ENDC}
  48.  
  49.     procedure Initialize (numberOfMasters: integer);
  50.         var
  51.             tempEvent: EventRecord;
  52.             junk_boolean: boolean;
  53.             i: integer;
  54.     begin
  55.         MaxApplZone();
  56.  
  57. {$IFC undefined THINK_Pascal}
  58.         for i := 1 to numberOfMasters do begin
  59.             MoreMasters;
  60.         end;
  61.         InitGraf(@qd.thePort);
  62.         InitFonts;
  63.         InitWindows;
  64.         InitMenus;
  65.         TEInit;
  66.         InitDialogs( nil );
  67. {$ENDC}
  68.  
  69.         InitCursor();
  70.         FlushEvents(everyEvent, 0);
  71.  
  72.         for i := 1 to 3 do begin
  73.             junk_boolean := EventAvail( everyEvent,  tempEvent );
  74.         end;
  75.     end;
  76.  
  77.  
  78. { /-------------------------------------------------------------------------------------- }
  79. {     ErrorAlert }
  80. { /-------------------------------------------------------------------------------------- }
  81.  
  82.     procedure ErrorAlert (err: OSErr; errorStringIndex: integer);
  83.         var
  84.             messageString, errorString: Str255;
  85.             dummy: longint;
  86.     begin
  87.         GetIndString(messageString, kErrorStringListResID, errorStringIndex);
  88.  
  89.         if (length(messageString) = 0) then
  90.             messageString := kSeriousDamageString;
  91. {BlockMove(Ptr(kSeriousDamageString), Ptr(messageString), sizeof(kSeriousDamageString));}
  92.  
  93.         NumToString(err, errorString);
  94.  
  95.         ParamText(messageString, errorString, '', '');
  96.  
  97.         dummy := StopAlert(kErrorAlertResID, nil);
  98.     end;
  99.  
  100.  
  101. { /-------------------------------------------------------------------------------------- }
  102. {     FatalError }
  103. { /-------------------------------------------------------------------------------------- }
  104.  
  105.     procedure FatalError (err: OSErr);
  106.     begin
  107.         if (err <> noErr) then
  108.             begin
  109.                 if (err = memFullErr) then
  110.                     ErrorAlert(err, kOutOfMemStringIndex)
  111.                 else
  112.                     ErrorAlert(err, kFatalErrorStringIndex);
  113.  
  114.                 ExitToShell;
  115.             end;
  116.     end;
  117.  
  118.  
  119. { /-------------------------------------------------------------------------------------- }
  120. {     CantFindResource }
  121. { /-------------------------------------------------------------------------------------- }
  122.  
  123.     procedure CantFindResource;
  124.         var
  125.             err: OSErr;
  126.     begin
  127.         err := ResError;
  128.  
  129.         if (err = noErr) then
  130.             err := resNotFound;
  131.  
  132.         ErrorAlert(err, kCantFindResourceStringIndex);
  133.  
  134.         ExitToShell;
  135.     end;
  136.  
  137.  
  138. { /-------------------------------------------------------------------------------------- }
  139. {     CantRunOnThisMachine }
  140. { /-------------------------------------------------------------------------------------- }
  141.  
  142.     procedure CantRunOnThisMachine;
  143.         var
  144.             dummy: longint;
  145.     begin
  146.         dummy := StopAlert(kCantRunAlertResID, nil);
  147.     end;
  148.  
  149. end.
  150.